//
//  SEFocusController.m
//  kuaiyi
//
//  Created by Alphts on 16/7/5.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SEFocusController.h"
#import "SEFocusModel.h"
#import "SEFocusCell.h"
#import "DoctorInfoController.h"

@interface SEFocusController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,weak)UITableView *tableView;
@property (nonatomic, strong) NSArray *focusList;

@end

static NSString *identifier = @"cell";

@implementation SEFocusController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITableView *tableView1 = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    
    _tableView = tableView1;
    
   [tableView1 setTableFooterView: [[UIView alloc] initWithFrame:CGRectZero]];
    
    //取消cell之间的分割线
    tableView1.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:_tableView];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    self.tableView.backgroundColor =[UIColor colorWithRed:247/265.0 green:247/265.0 blue:247/265.0 alpha:1.0];
    
    [self.tableView registerClass:[SEFocusCell class] forCellReuseIdentifier:identifier];
    
     [self setupUI];

}

-(void)setFocusList:(NSArray *)focusList{
    
    _focusList = focusList;
    
    [_tableView reloadData];
}


-(void)setupUI{

    [SENetworkReachabilityTool checkNetworkWithReachableBlock:^{
        
        [SEFocusModel focusListWithPVDAndSuccess:^(NSArray<SEFocusModel *> *focusList) {
            
            [SVProgressHUD dismiss];
            self.focusList = focusList;
            
        }];
    }];

}

#pragma mark
#pragma mark -代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.focusList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SEFocusCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    
    SEFocusModel *model = self.focusList[indexPath.row];
    
    cell.model = model;
    
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 110;
}

#pragma mark -- 跳转控制器
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    DoctorInfoController * doctorVC = [[DoctorInfoController alloc]init];
    
    
    doctorVC.fochusModel = self.focusList[indexPath.row];
    
    [self.navigationController pushViewController:doctorVC animated:YES];
    
    
    
    
    
}




@end
